package cn.edu.sdjzu.xg.eagle.util;

import com.github.yitter.contract.IIdGenerator;
import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.DefaultIdGenerator;

public class IdUtil {
	private IdUtil() {}
	static {
		IdGeneratorOptions options = new IdGeneratorOptions();
//        options.WorkerIdBitLength = 6;
//        options.SeqBitLength = 6;
//        options.TopOverCostCount = 2000;
		// options.MinSeqNumber = 5;
		// options.MaxSeqNumber = 200;

		options.Method = 1;
		options.BaseTime = 1582206693000L;
		options.WorkerId = 1;//机器号，同机号不重复

		 idGen = new DefaultIdGenerator(options);
	}
	private static final IIdGenerator idGen;
	private static int nextId=1000;

	/**
	 * https://mvnrepository.com/artifact/com.github.yitter/yitter-idgenerator/1.0.6
	 * Shorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID length,
	 * but also can have a very high instantaneous concurrent processing capacity (50W/0.1s),
	 * and powerful configuration capacity.
	 * 原方法newLong是线程安全的，没有这里getLongId没有使用synchronized
	 * @return
	 *
	 */
	public static Long getLongId(){
		return idGen.newLong();
	}

}
